package com.demo.service.serviceImpl;

import com.demo.common.Pager;
import com.demo.common.StringUtil;
import com.demo.dao.SysManagersDao;
import com.demo.model.SysManagers;
import com.demo.model.TabUsers;
import com.demo.service.SysManagersService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Service
public class SysManagersServiceImpl implements SysManagersService {

    @Resource
    private SysManagersDao dao;


    @Override
    public int total_managers() {
        return dao.total_managers();
    }

    @Override
    public void findAll(SysManagers t, HttpServletRequest request) {
        String url="sys_managers_view?loginname="+t.getLoginname()+"&username="+t.getUsername()+"&cardid="+t.getCardid()+"&tel="+t.getTel();
        int size=20;
        if(StringUtil.isNotEmpty(t.getLoginname()))
            t.setLoginname("%"+t.getLoginname()+"%");

        if(StringUtil.isNotEmpty(t.getUsername()))
            t.setUsername("%"+t.getUsername()+"%");

        if(StringUtil.isNotEmpty(t.getCardid()))
            t.setCardid(t.getCardid());

        if(StringUtil.isNotEmpty(t.getTel()))
            t.setTel(t.getTel());


        int rows=dao.countByExampleSearch(t);
        int cpage= request.getParameter("pager") == null ? 1 : Integer
                .parseInt(request.getParameter("pager"));
        if(cpage==0) {
            cpage=1;
        }
        String pager= Pager.getPagerStr(url, size, rows, cpage, 1);
        request.setAttribute("pager", pager);
        SysManagers query=new SysManagers(t.getLoginname(),t.getUsername(),t.getCardid(),t.getTel(),size*(cpage-1),size,"id","desc");
        List<SysManagers> list=dao.searchByPage(query);
        request.setAttribute("rows",rows);
        request.setAttribute("list", list);
    }

    @Override
    public boolean save(SysManagers s) {
        return dao.save(s);
    }

    @Override
    public List<SysManagers> find_check_loginname(String loginname) {
        return dao.find_check_loginname(loginname);
    }

    @Override
    public SysManagers findById(String id) {
        return dao.findById(id);
    }

    @Override
    public boolean update(SysManagers s) {
        return dao.update(s);
    }

    @Override
    public void del(String id) {
        dao.del(id);
    }

    @Override
    public void update_flag(SysManagers s) {
        dao.update_flag(s);
    }

    @Override
    public List<SysManagers> select_check_login(SysManagers s) {
        return dao.select_check_login(s);
    }

    @Override
    public List<SysManagers> findByLoginname(String loginname) {
        return dao.findByLoginname(loginname);
    }

    @Override
    public boolean update_tel(SysManagers s) {
        return dao.update_tel(s);
    }

    @Override
    public boolean update_password(SysManagers s) {
        return dao.update_password(s);
    }
}
